using System.Data;
using Mathmall.Administration.Data;
using Mathmall.Administration.Exceptions;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;

namespace Mathmall.Administration.Mapper;

public class RoleMapper : BaseMapper
{
    private readonly RoleManager<IdentityRole<int>> _roleManager;

    public RoleMapper(AdministrationContext context, RoleManager<IdentityRole<int>> roleManager) : base(context)
    {
        _roleManager = roleManager;
    }

    /// <summary>
    /// 创建角色
    /// </summary>
    /// <param name="role"></param>
    /// <returns></returns>
    public async Task<IdentityResult> AddRole(IdentityRole<int> role)
    {
        return await _roleManager.CreateAsync(role);
    }

    /// <summary>
    /// 查询全部角色信息
    /// </summary>
    /// <returns></returns>
    public IQueryable<IdentityRole<int>> QueryAllRoles()
    {
        return _context.Roles;
    }
}